<html>
  <head>   
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxSPW5CJgpdgO_s4yyMovOaVh_KvvhSfpvagV18eOyDWu7VytS6Bi1CWxw" type="text/javascript"></script>
    <script type="text/javascript">

        var map = null;
        var geocoder = null;

        function initialize() {
          if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(-23.548943, -46.638818),8);
            map.setUIToDefault();
            geocoder = new GClientGeocoder();
          }
        }


        function showAddress(address) {
          if (geocoder) {
            geocoder.getLatLng(
              address,
              function(point) {
                if (!point) {
                  alert(address + " não encontrado");
                } else {
                  map.setCenter(point, 15);
                  var marker = new GMarker(point, {draggable: true});
                  map.addOverlay(marker);
                  GEvent.addListener(marker, "dragend", function() {
                      document.forms[0].coords.value = marker.getLatLng().toUrlValue(6);
                    marker.openInfoWindowHtml(marker.getLatLng().toUrlValue(6));
                  });
                  GEvent.addListener(marker, "click", function() {
                      document.forms[0].coords.value = marker.getLatLng().toUrlValue(6);
                    marker.openInfoWindowHtml(marker.getLatLng().toUrlValue(6));
                  });
                  GEvent.trigger(marker, "click");
                }
              }
            );
          }
        }
        
        function informar(){ 
             window.opener.document.getElementById("form1:coords").value = document.forms[0].coords.value;
             window.opener.document.getElementById("form1:local").value = document.forms[0].coords.value;
             window.close();
        }
    </script>    
  </head>

  <body onload="initialize()" onunload="GUnload()">
    <form action="#" onsubmit="showAddress(this.address.value); return false">
      <p>
      Cidade:
        <input type="hidden" name="coords" /> 
        <input type="text" style="width:350px" name="address" value="Av. Paulista, 500" />
        <input type="submit" value="Procurar" />
        <input type="button" value="Informar" onclick="informar();" />
      </p>
      <div id="map_canvas" style="width: 600px; height: 400px"></div>
    </form>

  </body>
</html>
